//#include "StompedReality/Core//ComponentGroup.h"
#include "StompedReality/Core/Logger.h"
#include "StompedReality/Core/MessageSystem/MessageSystem.h"
namespace StompedReality
{
namespace Core
{
MessageSystem::MessageSystem( ) : StompedReality::GameAccess( )
{
}

MessageSystem::~MessageSystem( )
{
  LogCallFunctionInfo( "MessageSystem", "Destructor" );
  for ( MessageGroupVector::iterator iter = this->_msgGroups.begin( );
        iter != this->_msgGroups.end( ); ++iter )
  {
    delete *iter;
  }
}

bool MessageSystem::ReadFromFile ( const char* fileName )
{
  /*LogCallFunctionInfo("MessageSystem", "ReadFromFile" );
  Json::Value root = StompedReality::serialization::JsonHelper::createFromFile ( fileName );
  for ( unsigned i = 0; i < root["MessageGroups"].size( ); ++i )
  {
    Json::Value groupJson = root["MessageGroups"][i];
 LogCallFunctionSubInfo("Create ComponentGroup")
    if ( groupJson.get ( "type", "" ).asString( ).find ( "ComponentGroup" ) != -1 )
    {
      StompedReality::Core::ComponentGroup* grp =
        new StompedReality::Core::ComponentGroup( );
      grp->SetGame( this->m_Game );
      grp->setGroupID ( this->_msgGroups.size( ) );
      this->_msgGroups.push_back ( grp );
      grp->ParseJSON ( groupJson );
    }
  }*/

/*#ifdef DEBUG
  std::cout << "info\t[MessageSystem]\t[readFromFile]\tNum groups: " << this->_msgGroups.size( ) << std::endl;
#endif*/
  return true;
}

bool MessageSystem::sendToAll ( Message* msg )
{
  for ( MessageGroupVector::iterator iter = this->_msgGroups.begin( ); iter != this->_msgGroups.end( );
        ++iter )
  {
    ( *iter )->ProcessMessage ( msg );
  }
  return true;
}

StompedReality::Core::MessageGroup* MessageSystem::GetGroup( StompedReality::ID id )
{
  return this->_msgGroups[id];
}

}
}
